import { get, post } from '@/utils/http'
import type { BasicPagingListResult, BasicPagingListParams } from '@/apis/basicModel'
import type {
  GetListPlantResult,
  PostPlantAddParams,
  GetListDeviceResult,
  PostDeviceAddParams,
  PostDeviceEditParams
} from './model/factoryWorkshopMeterSetModel'
enum Api {
  /**
   * 工厂列表
   */
  GET_LIST_PLANT = '/thirdability/emsPlant/listPlant',
  /**
   * 新增工厂
   */
  ADD_PLANT = '/thirdability/emsPlant/addPlant',
  /**
   * 删除工厂
   */
  DELETE_PLANT = '/thirdability/emsPlant/deletePlant',
  /**
   * 车间列表
   */
  GET_LIST_DEPARTMENT = '/thirdability/emsDevice/listDepartment',
  /**
   * 分页查询仪表
   */
  GET_LIST_DEVICE = '/thirdability/emsDevice/pageDevice',
  /**
   * 新增仪表
   */
  ADD_DEVICE = '/thirdability/emsDevice/addDevice',
  /**
   * 编辑仪表
   */
  EDIT_DEVICE = '/thirdability/emsDevice/editDevice',
  /**
   * 删除仪表
   */
  DELETE_DEVICE = '/thirdability/emsDevice/deleteDevice'
}

/**
 * 工厂列表
 */
export const getListPlant = (): Promise<GetListPlantResult[]> => get(Api.GET_LIST_PLANT)

/**
 * 新建工厂
 */
export const postPlantAdd = (params: PostPlantAddParams): Promise<void> =>
  post(Api.ADD_PLANT, params)

/**
 * 删除工厂
 */
export const postPlantDelete = (plantNo: string): Promise<void> =>
  post(Api.DELETE_PLANT, { plantNo })

/**
 * 车间列表
 */
export const getListDepartment = (): Promise<string[]> => get(Api.GET_LIST_DEPARTMENT)

/**
 * 分页查询仪表
 * @param params
 * @returns
 */
export const getListDevice = (
  params: BasicPagingListParams & { plantNo: string }
): Promise<BasicPagingListResult<GetListDeviceResult>> => get(Api.GET_LIST_DEVICE, params)

/**
 * 新建仪表
 */
export const postDeviceAdd = (params: PostDeviceAddParams): Promise<void> =>
  post(Api.ADD_DEVICE, params)

/**
 * 编辑仪表
 */
export const postDeviceEdit = (params: PostDeviceEditParams): Promise<void> =>
  post(Api.EDIT_DEVICE, params)

/**
 * 删除仪表
 */
export const postDeviceDelete = (deviceNo: string): Promise<void> =>
  post(Api.DELETE_DEVICE, { deviceNo })
